package cn.schoolwow.util.module.check.instanceList.flow;

import cn.schoolwow.quickflow.domain.FlowContext;
import cn.schoolwow.quickflow.flow.BusinessFlow;
import cn.schoolwow.util.domain.query.instance.QueryInstance;

import java.util.List;

public class CheckInstanceListNotNullFlow implements BusinessFlow {
    @Override
    public void executeBusinessFlow(FlowContext flowContext) throws Exception {
        String fieldName = (String) flowContext.checkData("fieldName");
        List list = (List) flowContext.checkData("list");
        String message = (String) flowContext.checkData("message");

        for(Object instance:list){
            Object fieldValue = QueryInstance.newQuery(instance)
                    .execute()
                    .getSingleFieldValue(fieldName);
            if(null==fieldValue){
                throw new IllegalArgumentException(message+"不能为空");
            }
        }
    }

    @Override
    public String name() {
        return "实例列表-检查NULL字段";
    }
}
